package com.storage.mongo;

import java.net.UnknownHostException;
import java.util.List;

import com.google.code.morphia.query.Query;
import com.mongodb.MongoException;

public class DBInterface {
	
	DiscussionForum df;
	CharityForum cf;
	
	public DBInterface() throws UnknownHostException, MongoException
	{
		df = new DiscussionForum();
		cf= new CharityForum();
	}
	
	//discussion forum interface methods
	
	public void createTopic(String topicTitle,String topicContent,String createdUser,String communityID) throws UnknownHostException, MongoException
	{	
		//sample data
		//df.createTopic("China news","Post some news in india","prk","ABPM");
		df.createTopic(topicTitle,topicContent,createdUser,communityID);
	}
	
	public void addComments(String topicTitle,String userName,String comments) throws UnknownHostException, MongoException
	{	
		//sample data
		//df.addComments("China News","babu","comments babu");
		df.addComments(topicTitle,userName,comments);
	}
	
	
	public Query<ETopic> getComments(String topicTitle)
	{
		Query<ETopic> query = df.getComments(topicTitle);
		return query;
	}

	public Query<ETopic> getTopics()
	{
		Query<ETopic> query = df.getTopics();
		System.out.println("main fun title111");
		for(ETopic t : query)
		{
			System.out.println("main fun title"+ t.getTopicTitle());
		}
		return query;
	}
	
	
	//charity interface methods
	
	public  void createCharity(String charityName,String charityDescription,String createdUser,String communityID) throws UnknownHostException, MongoException 
	{
		cf.createCharity(charityName, charityDescription, createdUser, communityID);
		
	}
	
	public  void donateCharity(String charityName,int donatedAmount,String donatedBy,String communityID) throws UnknownHostException, MongoException
	{

		cf.donateCharity(charityName, donatedAmount, donatedBy, communityID);
	}
	public  Query<Echarity> getCharityDetails(String charityName)
	{
		
		Query<Echarity> query = cf.getCharityDetails(charityName);
		
		return query;
	}
	
	public List<Echarity> listCharity()
	{
		List<Echarity> list = cf.listCharity();
		return list;
	}
	
	public int getTotalDonation(String charityName)
	{
		int totalAmount = cf.getTotalDonation(charityName);
		return totalAmount;

	}

}
